\section{trace --- trace of a matrix}
\label{fn:trace}
\index{trace()}
\index{trace of a matrix}
\index{matrix!trace}
\begin{rail}
Trace : 'trace' '(' Matrix ')' ;
\end{rail}

\verb+trace+ returns the trace of the argument matrix.  This is the
sum of the terms on the main diagonal.

$\Longrightarrow$ This is not an \RLaB\ built-in function.  This function
is normally loaded on start-up from the \verb+trace.r+ file in the
standard \verb+rlib+ directory. Use of the \verb+-r+ option, incorrectly 
setting the \verb+RLAB_LIB_DIR+ environmental variable, or modifying
\verb+trace.r+ may make this function unavailable.

\paragraph{Example}
\index{example of trace()}
\index{trace()!example}
\begin{verbatim}
> a = rand(3,3)
 a =
        1      0.333      0.665  
    0.975     0.0369     0.0847  
    0.647      0.162      0.204  
> trace(a)
     1.24
> 1+0.0369+0.204
     1.24
> trace(eye(5,5))
        5
\end{verbatim}

See also: Page~\pageref{fn:sum} \verb+sum()+.

\newpage



